<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="{{ctx}}/static/bsl/js/ajaxfileupload.js"
	type="text/javascript"></script>
</head>
<body>
	<form id="packCert">
		<input class="In" type="hidden" id="appid" value="{{appId}}"
			name="appid" /> <input class="In" type="hidden" id="plat"
			value="{{platform}}" name="platid" />
		<div class="mar-st-a30">
			<table border="0" cellpadding="0" cellspacing="0" id="androidTable"
				class=" width100 bd">
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>上传证书：</td>
					<td class="bd_sr"><input type="file" name="file"
						id="inputcerfile"
						onchange="ajaxFileUpload('inputcerfile','inputcer')" /> <input
						class="In" type="hidden" id="inputcer" value="" name="certid" /></td>
				</tr>
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>上传密钥：</td>
					<td class="bd_sr"><input type="text" id="inputkey" value=""
						class="form-control  wid50" name="certkey" /></td>
				</tr>
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>证书别名：</td>
					<td class="bd_sr"><input type="text" id="keyAlias" value=""
						class="form-control  wid50" name="keyAlias" /></td>
				</tr>
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>密码：</td>
					<td class="bd_sr"><input type="text" name="storePass"
						id="storePass" class="form-control  wid50" /></td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="0" id="iosTable"
				class=" width100 bd">
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>发布证书：</td>
					<td class="bd_sr"><input type="file" name="file"
						id="inputcerfile"
						onchange="ajaxFileUpload('inputcerfile','inputcer')" /> <input
						class="In" type="hidden" id="inputcer" value="" name="certid" /></td>
				</tr>
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>mobile.provision：</td>
					<td class="bd_sr"><input type="file" name="file"
						id="inputkeyfile"
						onchange="ajaxFileUpload('inputkeyfile','certkey')" /> <input
						class="In" type="hidden" id="certkey" value="" name="certkey" />
					</td>
				</tr>
				<tr style="line-height: 40px">
					<td align="right"><span class="font-red">*</span>证书密码：</td>
					<td class="bd_sr"><input type="text" name="storePass"
						id="storePass" class="form-control  wid50" /></td>
				</tr>
			</table>
		</div>
	</form>
</body>
</html>
<script type="text/javascript">
	var popover = function(inputId, content) {
		var options = {
			placement : "bottom",
			content : content
		};
		$('#' + inputId).attr("data-toggle", "popover");
		$('#' + inputId).popover(options);
		$('#' + inputId).popover('show');
	}
	var plat = $('#plat').val();
	if (plat == "android") {
		$('#iosTable').remove();
	} else {
		$('#androidTable').remove();
	}

	var ajaxFileUpload = function ajaxFileUpload(fileid, inputId) {
		var url = "{{ctx}}/mam/attachment/upload";
		var fileidValue = $('#' + fileid).val();
		var platform = $('#platformid').val();
		/*
		var tel;
		if (platform == "ios") {
			tel = /.ipa$/;
			if (!tel.test(fileidValue)) {
				popover(fileid, "证书文件格式不正确，请重新上传。");
				return false;
			}
		} else if (platform == "android") {
			tel = /.cer$/;
			if (!tel.test(fileidValue)) {
				popover(fileid, "证书文件格式不正确，请重新上传。");
				return false;
			}
		}
		 */
		$.ajaxFileUpload({
			url : url,
			secureuri : false,
			fileElementId : fileid,
			dataType : 'json',
			success : function(data, status) {
				if (data.result == "success") {
					$('#' + inputId).val(data.id)
				} else {
					bootbox.alert("上传失败，请稍后再试！");
				}
			},
			error : function(data, status, e) {
				console.log(e);
				bootbox.alert("系统繁忙，请稍后再试！");
			}
		})
		return false;
	}

	//保存证书信息
	function secretSubmit() {
		var data = $('#packCert').serialize();
		$.ajax({
			async : true,
			type : "POST",
			url : "{{ctx}}/mam/secret/{{platform}}?appId={{appId}}",
			data : data,
			dataType : 'json',
			success : function(data, textStatus) {
				if (data.result == "success") {
					$('#infosecret').text("已配置");
					$('#secretHidden').val("true");
				} else {
					bootbox.alert("系统繁忙，请稍后再试！");
				}
			},
			error : function(data, status, e) {
				bootbox.alert("系统繁忙，请稍后再试！");
			}
		});
	}

	/*
	function packformSubmit(obj, type) {
		var localCert = $('#localCert').val();
		var flag = true;
		if (localCert == "1") {
			if ($("#certid").val() == "") {
				popover('inputcerfile', "证书文件格式不正确，请重新上传。");
				flag = false;
			}
			if ($("#inputkey").val() == "") {
				popover('inputkey', "密钥不能为空");
				flag = false;
			}
			if ($("#keyAlias").val() == "") {
				popover("keyAlias", "别名不能为空");
				flag = false;
			}
			if ($("#storePass").val() == "") {
				popover("storePass", "密码不能为空");
				flag = false;
			}
		}
		if (flag == true) {
			var data = $('#packCert').serialize();
			$.ajax({
				async : true,
				type : "POST",
				url : "{{ctx}}/mam/pkg/{{platform}}?appId={{appId}}",
				data : data,
				dataType : 'json',
				success : function(data, textStatus) {
					if (data.result == "success") {
						packrequest(obj, type);
					} else {
						bootbox.alert("系统繁忙，请稍后再试！");
					}
				},
				error : function(data, status, e) {
					bootbox.alert("系统繁忙，请稍后再试！");
				}
			});
		} else {
			bootbox.alert("信息没有填写完，请重新填写");
		}
	}
	 */
</script>
